﻿var checkStudentCode = 0;
 
$(function () {
    $("#stu_table").hide();
})
var checkNumber=0;
//根据id来判断学生
function CheckByCode(idName) {
    checkNumber = 0;
    var code = $("#" + idName).val();
    var ConId = $("#ConId").val();
    if (code != "") {
        $.ajax({
            type: "POST", //用POST方式传输
            dataType: "json", //数据格式:JSON
            url: "../tool/CheckStudent.ashx", //目标地址
            data: "STU_CODE=" + code + "&ConId=" + ConId,
            //beforeSend:function(){$("#divload").show();$("#Pagination").hide();},//发送数据之前,显示loading gif,隐藏数据
            //complete:function(){$("#divload").hide();$("#Pagination").show()},//接收数据完毕
            success: function (json) {
                checkNumber = checkNumber + 1;
                var content = "<td>" + json.tempTable[0].STU_CODE + "</td><td>" + json.tempTable[0].STU_NAME + "</td><td>" + json.tempTable[0].CLA_NAME + "</td><td>" + json.tempTable[0].ACA_NAME + "</td>";
                $("#ParId").val(json.tempTable[0].PAR_ID);
                $("#stu_infor").html(content);
                $("#stu_table").show();
            },
            error: function (e) {
                alert(e.responseText);
            }
        });
    }
    else {
        alert("学号不允许为空");
        
    }
}

function CheckByCodeSecond(idName) {
    checkNumber = 0;
    var code = $("#" + idName).val();
    var ConId = $("#ConId").val();
    if (code != "") {
        $.ajax({
            type: "POST", //用POST方式传输
            dataType: "json", //数据格式:JSON
            url: "../../tool/CheckStudent.ashx", //目标地址
            data: "STU_CODE=" + code + "&ConId=" + ConId,
            //beforeSend:function(){$("#divload").show();$("#Pagination").hide();},//发送数据之前,显示loading gif,隐藏数据
            //complete:function(){$("#divload").hide();$("#Pagination").show()},//接收数据完毕
            success: function (json) {
                checkNumber = checkNumber + 1;
                var content = "<td>" + json.tempTable[0].STU_CODE + "</td><td>" + json.tempTable[0].STU_NAME + "</td><td>" + json.tempTable[0].CLA_NAME + "</td><td>" + json.tempTable[0].ACA_NAME + "</td>";
                $("#ParId").val(json.tempTable[0].PAR_ID);
                $("#stu_infor").html(content);
                $("#stu_table").show();
            },
            error: function (e) {
                alert(e.responseText);
            }
        });
    }
    else {
        alert("学号不允许为空");

    }
}

//根据小组名称来获取相应的信息
function CheckByGroup(idName) {
    var GroupName = $("#" + idName).val();
    var ConId = $("#ConId").val();
    if (GroupName != "") {
        $.ajax({
            type: "POST", //用POST方式传输
            dataType: "json", //数据格式:JSON
            url: "../../tool/CheckGroup.ashx", //目标地址
            data: "GroupName=" + GroupName + "&ConId=" + ConId,
            //beforeSend:function(){$("#divload").show();$("#Pagination").hide();},//发送数据之前,显示loading gif,隐藏数据
            //complete:function(){$("#divload").hide();$("#Pagination").show()},//接收数据完毕
            success: function (json) {
                checkNumber = checkNumber + 1;
                var tbody = "";
                var productData = json.tempTable;
                $.each(productData, function (i, n) {
                    tbody = tbody + "<tr><td>" + n.STU_CODE + "</td><td>" + n.STU_NAME + "</td><td>" + n.CLA_NAME + "</td><td>" + n.ACA_NAME + "</td></tr>";
                });
                $("#ParId").val(productData[0].GRO_ID);
                $("#stu_infor").replaceWith(tbody);
                $("#stu_table").show();
            },
            error: function (e) {
                alert(e.responseText);
            }
        });
    }
    else {
        alert("小组名称不允许为空");
    }
}
//添加成员
function AddStuSubmit() {
    if (checkNumber > 0) {
        return true;
    }
    else {
        alert("请先查询学生学号是否可用");
        return false;
    }
}
//添加小组
function AddGroup()
{ 
    if (checkNumber > 0) {
        return true;
    }
    else {
        alert("请先查询小组是否可用");
        return false;
    }
}

//根据id来判断学生
function GetStudentsByCode(idName) {
    checkStudentCode = 0;
    var code = $("#" + idName).val();
    if (code != "") {
        $.ajax({
            type: "POST", //用POST方式传输
            dataType: "json", //数据格式:JSON
            url: "../../tool/CheckStudnetByCode.ashx", //目标地址
            data: "STU_CODE=" + code,
            //beforeSend:function(){$("#divload").show();$("#Pagination").hide();},//发送数据之前,显示loading gif,隐藏数据
            //complete:function(){$("#divload").hide();$("#Pagination").show()},//接收数据完毕
            success: function (json) {
                checkStudentCode = checkStudentCode + 1;
                var content = "<td>" + json.STU_CODE + "</td><td>" + json.STU_NAME + "</td><td>" + json.classes.CLA_NAME + "</td><td>" + json.academy.ACA_NAME + "</td>";
                $("#ParId").val(json.PAR_ID);
                $("#stu_infor").html(content);
                $("#stu_table").show();
            },
            error: function (e) {
                alert(e.responseText);
            }
        });
    }
    else {
        alert("学号不允许为空");

    }
}

function CheckAddStudent() {
    if (checkStudentCode > 0) {
        return true;
    }
    else {
        alert("请先检测是否存在此学生");
        return false;
    }
}
